import {
    LoginStatus,
    LoginOut
} from '@/library/api/api'

export default {
    data() {
        return {
            isColor:"#EC4141",
            n:false,
            login:false,
            show:false,
            set:false,
            checked:true,
            userName:"点击登录",
            userAva:"",
        }
    },
    methods: {
        Status() {
            LoginStatus({
                data: {
                    cookie:localStorage.cookie
                }
            }).catch(error=>{
                if(error.response.data.data.profile==="null") {
                    console.log("未登录");
                }else if (error.response.data.data.profile) {
                    console.log("已登录");
                    let faUser = document.getElementById('faUser')
                    faUser.classList=""
                    this.userName = error.response.data.data.profile.nickname,
                    this.userAva = error.response.data.data.profile.avatarUrl
                }
            })
        },
        logout() {
            LoginOut({}).then(res=>{
                if(res.code=="200") {
                    delete localStorage.cookie
                    delete localStorage.uid
                    this.set = false
                    location.reload();
                }
            })
        },
        changeColor() {
            if(this.n === false) {
                this.isColor = "#EC4141"
            }else {
                this.isColor = "#45A9F9"
            }
            this.n = !this.n
            return this.isColor,this.n
        },
        Login() {
            this.show = !this.show
            return this.show
        },
        setting() {
            this.set = !this.set
            return this.set
        },
        getUserName(data) {
            this.userName = data
        },
        getUserAva(data) {
            this.userAva = data
            let faUser = document.getElementById('faUser')
            faUser.classList=""
        },
        getN(data) {
            this.show = data
            this.login = !data
        },
        checkT() {
            this.checked = true
        },
        checkF() {
            this.checked = false
        }
    },
    created() {
        this.changeColor(),
        this.Status()
    }
}